/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			CC_Cmd.h
  \date			June 2011
  \author		TNick

  \brief		Contains the definition for CC_Cmd class


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @n
 Please read ReadMe.txt and Licence.txt in root folder @n
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @n

*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef __CC_CMD_INC__
#define __CC_CMD_INC__
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	<QString>
#include	<QStringList>
#include	<QPoint>

/*  INCLUDES    ============================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

/// class that describes a general purpose command
/**
*	Using static members, this class is also responsable for the management
*	of commands inside an instance. @n
*	Commands may be provided by:
*	- core: these are internal functions exposed to the user by the application
*	- plug-ins: each module that is loaded has the opportunity to append a
*	single array of commands
*	Each ommand has an unique ID associated with it. This ID is a 32-bit value
*	that stores two elements: the unique ID of the Plug-In and the index of the
*	command in the array of commands owned by that plug-in.
*	The ID for plug-ins is asigned at load time.
*/
class CC_Cmd 		{

    //
    //
    //
    //
    /*  DEFINITIONS    ----------------------------------------------------- */
public:
    /// values that identify types of commands
    enum	CMDTY		{
        TY_COMMAND,	/**< actual command */
        TY_TEXT,	/**< text input/output */
        TY_BOOL,	/**< two possible values: t/f*/
        TY_COMBO,	/**< list of possible values */

        TY_MAX
    };

    /// asign an unique number to each mouse event
    enum	MTYP		{
        /// a click event
        MTY_CLICK,
        MTY_2CLICK,
        MTY_MOVE,

        MTY_MAX
    };

    /// structure that groups all there is to know about a mouse event
    struct	CmdMouse	{
        /// the type of the event
        MTYP		ty;
        /// location of the event
        QPoint		loc;
        /// the index of the buttoon
        int			btn;


        /// default constructor
        CmdMouse()
        {
            ty = MTY_CLICK;
            loc = QPoint(0,0);
            btn = 0;
        }
    };

	/* following commands are assigned to slots in the same 
	order as presented here.
	The typedefs are usable by plug-ins; to call a functin from 
	application, use the functions. */
	
    /// function used with TY_COMMAND; the user has started the command
    typedef		void		(*pt_Cmd_Trigger)		(QStringList args);
    /// function used with TY_COMMAND; the user has ended the command
    typedef		void		(*pt_Cmd_End)			(void);
    /// function used with TY_COMMAND; a mouse event of some
    typedef		void		(*pt_Cmd_Mouse)			(const CmdMouse* p_mdata);
    /// function used with TY_COMMAND; an option or command string
    typedef		void		(*pt_Cmd_Opt)			(QString cmd);


    /// function used with TY_TEXT; the user requests stored value
    typedef		QString		(*pt_TX_Get)            (void);
    /// function used with TY_TEXT; the user has set a new value
    /**
      * @return if new value is acceptable, returns true; otherwise false
      */
    typedef		bool        (*pt_TX_Set)            (QString s_new);


    /// function used with TY_BOOL; the user requests stored value
    typedef		bool		(*pt_Bl_Get)            (void);
    /// function used with TY_BOOL; the user has set a new value
    typedef		void        (*pt_Bl_Set)            (bool b_new);


    /// function used with TY_COMBO; the user requests stored value
    typedef		int 		(*pt_Cb_Get)            (void);
    /// function used with TY_COMBO; the user has set a new value
    typedef		void        (*pt_Cb_Set)            (int i_new);
    /// function used with TY_COMBO; the user requests the list of options
    typedef		QStringList	(*pt_Cb_List)            (void);

	
	
	
	
    /*  DEFINITIONS    ===================================================== */
    //
    //
    //
    //
    /*  DATA    ------------------------------------------------------------ */

private:
    /// the type of this command
    CMDTY			type;

    /// the name (or informative text) for this command
    QString			name;

    /// first slot for function calling
    /**
*	- for regular commands (do like commands), this is the slot used to start it
*	- for text "commands", this will report the value (string)
*	- for boolean "commands", this will report the value (boolean)
*	- for combo "commands", this will tell the index (integer) of current value
*/
    void*			slot_1;


    /// second slot for function calling
    /**
*	this handles cancel requests
*/
    void*			slot_2;


    /// third slot for function calling
    /**
   *	This is required to customly display the item
   */
    void*			slot_3;

    /// fourth slot for function calling
    void*			slot_4;





    /*  DATA    ============================================================ */
    //
    //
    //
    //
    /*  FUNCTIONS    ------------------------------------------------------- */

public:

    /// the constructor
    CC_Cmd(
        CMDTY		in_type,
        QString		in_name,
        void*		in_slot_1,
        void*		in_slot_2,
        void*		in_slot_3,
        void*		in_slot_4)
    {
        type = in_type;
        name = in_name;
        slot_1 = in_slot_1;
        slot_2 = in_slot_2;
        slot_3 = in_slot_3;
        slot_4 = in_slot_4;
    }


	/* functions that call associated commands */
	
    /// function used with TY_COMMAND; the user has started the command
    /// function used with TY_COMMAND; the user has started the command
    inline void		cmd_Trigger		(QStringList args)
{
	((pt_Cmd_Trigger)slot_1)(args);
}
    /// function used with TY_COMMAND; the user has ended the command
    inline void		cmd_End			(void)
{
	((pt_Cmd_End)slot_2)();
}
    /// function used with TY_COMMAND; a mouse event of some
    inline void		cmd_Mouse			(const CmdMouse* p_mdata)
{
	((pt_Cmd_Mouse)slot_3)(p_mdata);
}
    /// function used with TY_COMMAND; an option or command string
    inline void		cmd_Opt			(QString cmd)
{
	((pt_Cmd_Opt)slot_4)(cmd);
}


    /// function used with TY_TEXT; the user requests stored value
    inline QString		tx_Get            (void)
{
	return ((pt_TX_Get)slot_1)();
}
    /// function used with TY_TEXT; the user has set a new value
    /**
      * @return if new value is acceptable, returns true; otherwise false
      */
    inline bool        tx_Set            (QString s_new)
{
	((pt_TX_Set)slot_2)(s_new);
}


    /// function used with TY_BOOL; the user requests stored value
    inline bool		   bl_Get            (void)
{
	return ((pt_Bl_Get)slot_1)();
}
    /// function used with TY_BOOL; the user has set a new value
    inline void        bl_Set            (bool b_new)
{
	((pt_Bl_Set)slot_2)(b_new);
}


    /// function used with TY_COMBO; the user requests stored value
    inline int 		   cb_Get            (void)
{
	return ((pt_Cb_Get)slot_1)();
}
    /// function used with TY_COMBO; the user has set a new value
    inline void        cb_Set            (int i_new)
{
	((pt_Cb_Set)slot_2)(i_new);
}
    /// function used with TY_COMBO; the user requests the list of options
    inline QStringList	cb_List            (void)
{
	return ((pt_Cb_List)slot_3)();
}
    /*  FUNCTIONS    ======================================================= */
    //
    //
    //
    //

};	/*	class CC_Cmd	*/

/*  CLASS    =============================================================== */
//
//
//
//
#endif // __CC_CMD_INC__
/* ------------------------------------------------------------------------- */
/* ========================================================================= */

